﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace ResourceBlender.Core {
    public class WordDefinition : IComparable<WordDefinition> {
        /// <summary>
        /// Gets or sets the type of this definition.
        /// </summary>
        /// <value>The type of the definition.</value>
        public string DefinitionType { get; set; }

        /// <summary>
        /// Gets or sets the definitions for this word.
        /// </summary>
        /// <value>The definitions.</value>
        public List<string> Meanings { get; set; }
        public WordDefinition() {
            DefinitionType = string.Empty;
            Meanings = new List<string>();
        }

        public int CompareTo(WordDefinition other) {
            if(other == null) {
                return 1;
            } else {
                int numMeaningsComparison = this.Meanings.Count.CompareTo(other.Meanings.Count);
                return numMeaningsComparison == 0 ? string.Compare(this.DefinitionType, other.DefinitionType, true, System.Globalization.CultureInfo.InvariantCulture) : numMeaningsComparison;
            }
        }
    }

    public class DefinitionCollection : INotifyPropertyChanged {
        private string definedWord, serviceUrl;
        private List<WordDefinition> defs;

        public string DefinedWord {
            get { return definedWord; }
            set {
                definedWord = value;
                OnPropertyChanged("DefinedWord");
            }
        }

        public string ServiceUrl {
            get { return serviceUrl; }
            set {
                serviceUrl = value;
                OnPropertyChanged("ServiceUrl");
            }
        }

        public List<WordDefinition> Definitions {
            get { return defs; }
            set {
                defs = value;
                OnPropertyChanged("Definitions");
            }
        }

        public DefinitionCollection() {
            defs = new List<WordDefinition>();
        }

        public event PropertyChangedEventHandler PropertyChanged;
        protected virtual void OnPropertyChanged(string strPropertyName) {
            if(PropertyChanged != null) {
                PropertyChanged(this, new PropertyChangedEventArgs(strPropertyName));
            }
        }
    }
}
